#include "comm.h"


int main()
{
    key_t Key = GetKey();
    int shmid = GetShm(Key);
    char *s = (char*)shmat(shmid, nullptr, 0);
    std::cout << "attach shm done" << std::endl;
    int fd = open(FILENAME.c_str(), O_WRONLY);
    // sleep(10);
    //char c = 'a';
    //for(; c <= 'z'; c++)
   // {
   //     s[c-'a'] = c;
   //     std::cout << "write : " << c << " done" << std::endl;
   //     sleep(1);

   //     // 通知对方
   //     int code = 1;
   //     write(fd, &code, sizeof(4));
   // }
    std::string message = "I am Process A";
    while(true)
    {
        strcpy(s,message.c_str());
        int code = 1;
        write(fd,&code,sizeof(4));
    }

    shmdt(s);
    std::cout << "detach shm done" << std::endl;
    close(fd);
    return 0;
}
